Skip to content

fix(core): harden file permissions for user config directory#328

Merged
drew merged 1 commit intomainfrom
user-config-perms
Mar 15, 2026
Merged

fix(core): harden file permissions for user config directory#328
drew merged 1 commit intomainfrom
user-config-perms

Conversation

@drew
Copy link
Collaborator

@drew drew commented Mar 15, 2026

Summary

Sensitive files in the OpenShell config directory (~/.config/openshell/) were created with default umask permissions (typically 0o644 for files, 0o755 for directories), making mTLS private keys and auth tokens world-readable on multi-user systems.

Changes

  • New openshell_core::paths module with centralized XDG config resolution and permission helpers (create_dir_restricted 0o700, set_file_owner_only 0o600, is_file_permissions_too_open)
  • mTLS private key hardened (mtls.rs): tls.key now set to 0o600 immediately after writing; temp and final mtls/ directories created with 0o700
  • All config directories hardened: openshell/, gateways/<name>/, forwards/, SSH config parent -- all created with 0o700 via create_dir_restricted
  • Legacy token migration: load_edge_token() now migrates legacy cf_token files to the new edge_token path with proper 0o600 permissions and removes the insecure legacy file
  • XDG path deduplication: Replaced 5 duplicate xdg_config_dir() implementations across openshell-bootstrap, openshell-cli, openshell-core, and openshell-tui with a single canonical version in openshell-core::paths

Testing

  • mise run pre-commit passes (format fixed, one pre-existing test failure unrelated -- port 8080 occupied locally)
  • Unit tests added for all new permission helpers (create_dir_restricted_sets_0o700, set_file_owner_only_sets_0o600, is_file_permissions_too_open_*)
  • All 109 existing tests pass (69 bootstrap + 40 core)
  • E2E tests added/updated (not applicable -- permission changes are transparent to sandbox behavior)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@drew drew self-assigned this Mar 15, 2026
@drew drew added the test:e2e Requires end-to-end coverage label Mar 15, 2026
Sensitive files in the OpenShell config directory (~/.config/openshell/)
were created with default umask permissions, making them world-readable.
This is a security concern for mTLS private keys (tls.key) and auth
tokens.

- Add centralized paths module to openshell-core with permission helpers
  (create_dir_restricted 0o700, set_file_owner_only 0o600)
- Set 0o600 on tls.key in mtls.rs (was inheriting umask, typically 0o644)
- Set 0o700 on all config directories (mtls/, gateways/, forwards/, etc.)
- Migrate legacy cf_token files to new edge_token path with proper perms
- Deduplicate xdg_config_dir() from 6 locations into openshell-core
@drew drew force-pushed the user-config-perms branch from aead339 to 850c387 Compare March 15, 2026 21:11
@drew drew requested review from johntmyers and pimlock March 15, 2026 21:13
Copy link
Collaborator

@pimlock pimlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@drew drew force-pushed the user-config-perms branch 2 times, most recently from d1af0a5 to 850c387 Compare March 15, 2026 22:13
@drew drew merged commit 9bda380 into main Mar 15, 2026
24 of 26 checks passed
@drew drew deleted the user-config-perms branch March 15, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:e2e Requires end-to-end coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants